package l1j.server.server.datatables;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import l1j.server.L1DatabaseFactory;
import l1j.server.server.utils.SQLUtil;
import l1j.server.server.utils.collections.Maps;

public class EnchantWeaponAdvance {
	private static EnchantWeaponAdvance _instance;

	public static EnchantWeaponAdvance getInstance() {
		return _instance;
	}

	public static void initilize() {
		_instance = new EnchantWeaponAdvance();
	}

	private Map<Integer, WeaponEnchantAdvance> _allEffects = Maps.newMap();

	private EnchantWeaponAdvance() {
		Connection con = null;
		PreparedStatement pstm = null;
		ResultSet rs = null;
		try {
			con = L1DatabaseFactory.getInstance().getConnection();
			pstm = con.prepareStatement("SELECT * FROM enchant_advance_weapon");

			rs = pstm.executeQuery();
			while (rs.next()) {
				WeaponEnchantAdvance we = new WeaponEnchantAdvance();
				we.setExtra_phy_dmg(rs.getInt("extra_phy_dmg"));
				we.setExtra_magic_dmg(rs.getInt("extra_magic_dmg"));
				we.setCritical_phy_chance(rs.getInt("critical_phy_chance"));
				we.setCritical_phy_rate(rs.getInt("critical_phy_rate"));
				we.setCritical_magic_chance(rs.getInt("critical_magic_chance"));
				we.setCritical_magic_rate(rs.getInt("critical_magic_rate"));
				we.setAddstr(rs.getInt("str"));
				we.setAdddex(rs.getInt("dex"));
				we.setAddint(rs.getInt("int"));
				we.setAddcon(rs.getInt("con"));
				we.setAddwis(rs.getInt("wis"));
				we.setAddcha(rs.getInt("cha"));
				_allEffects.put(rs.getInt("enchant_level"), we);
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			SQLUtil.close(rs);
			SQLUtil.close(pstm);
			SQLUtil.close(con);
		}
	}

	public WeaponEnchantAdvance getAdvance(int enchantLevel) {
		WeaponEnchantAdvance wea = _allEffects.get(enchantLevel);
		if (wea == null) {
			_allEffects.put(enchantLevel, new WeaponEnchantAdvance());
			return _allEffects.get(enchantLevel);
		}
		return wea;
	}

	public class WeaponEnchantAdvance {
		private int extra_phy_dmg = 0;
		private int extra_magic_dmg = 0;
		private int critical_phy_chance = 0;
		private int critical_phy_rate = 0;
		private int critical_magic_chance = 0;
		private int critical_magic_rate = 0;
		private int addstr = 0;
		private int adddex = 0;
		private int addint = 0;
		private int addcon = 0;
		private int addwis = 0;
		private int addcha = 0;

		public int getExtra_phy_dmg() {
			return extra_phy_dmg;
		}
		
		public void setExtra_phy_dmg(int extra_phy_dmg) {
			this.extra_phy_dmg = extra_phy_dmg;
		}
		
		public int getExtra_magic_dmg() {
			return extra_magic_dmg;
		}
		
		public void setExtra_magic_dmg(int extra_magic_dmg) {
			this.extra_magic_dmg = extra_magic_dmg;
		}
		
		public int getCritical_phy_chance() {
			return critical_phy_chance;
		}

		public void setCritical_phy_chance(int critical_phy_chance) {
			this.critical_phy_chance = critical_phy_chance;
		}

		public int getCritical_phy_rate() {
			return critical_phy_rate;
		}

		public void setCritical_phy_rate(int critical_phy_rate) {
			this.critical_phy_rate = critical_phy_rate;
		}

		public int getCritical_magic_chance() {
			return critical_magic_chance;
		}

		public void setCritical_magic_chance(int critical_magic_chance) {
			this.critical_magic_chance = critical_magic_chance;
		}

		public int getCritical_magic_rate() {
			return critical_magic_rate;
		}

		public void setCritical_magic_rate(int critical_magic_rate) {
			this.critical_magic_rate = critical_magic_rate;
		}

		public int getAddstr() {
			return addstr;
		}

		public void setAddstr(int addstr) {
			this.addstr = addstr;
		}

		public int getAdddex() {
			return adddex;
		}

		public void setAdddex(int adddex) {
			this.adddex = adddex;
		}

		public int getAddint() {
			return addint;
		}

		public void setAddint(int addint) {
			this.addint = addint;
		}

		public int getAddcon() {
			return addcon;
		}

		public void setAddcon(int addcon) {
			this.addcon = addcon;
		}

		public int getAddwis() {
			return addwis;
		}

		public void setAddwis(int addwis) {
			this.addwis = addwis;
		}

		public int getAddcha() {
			return addcha;
		}

		public void setAddcha(int addcha) {
			this.addcha = addcha;
		}
	}
}
